﻿using Models;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.UI.WebControls.WebParts;
using wnet.admin.Models.dto;
using wnet.admin.wentcommon;




namespace wnet.admin.Controllers.pcapi
{

    [Route("business/adminlogin/{action}")]
    public class adminloginController : ApiController
    {

        private readonly ISqlSugarClient _sqlSugarClient;
        public adminloginController()
        {
            _sqlSugarClient = SqlSugarConfig.CreateClient();
        }

        ///// <summary>
        ///// 管理员信息获取
        ///// </summary>
        ///// <returns></returns>
        //[TokenAuth]
        //[HttpGet]
        //public object getInfo()
        //{

        //    var user = _sqlSugarClient.Queryable<sys_user>().Where(q => q.id == 1).First();
        //    //前端校验按钮权限使用
        //    //角色集合 eg: admin,yunying,common
        //    List<string> roles = new List<string>();
        //    roles.Add("admin");
        //    //权限集合 eg *:*:*,system:user:list
        //    List<string> permissions = new List<string> { "*:*:*" };

        //    return new { code = 200, msg = "成功", data = new { user, roles, permissions } };
        //}


     



        /// <summary>
        /// 登入
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object login(logindto entity)
        {

            List<object> list = new List<object>();

            string Password = tools.GetMD5Hash(entity.password);
            var user = _sqlSugarClient.Queryable<sys_user>().Where(q => q.loginpwd == Password && q.loginname == entity.username).First();
            if (user == null)
            {
                return new { code = 105, msg = "账号密码错误", data = "错误" };
            }
            string token = tools.Gettoken(user.id.ToString());
            return new { code = 200, msg = "成功", data = token };



        }




    }
}
